package com.qf.routing;

import com.qf.util.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

/**
 * DIRECT类型Exchange
 */
public class Publisher {

    @Test
    public void publish() throws Exception {
        //1. c
        Connection connection = ConnectionUtil.getConnection();

        //2. c
        Channel channel = connection.openChannel().get();

        //3. declare Exchange
        channel.exchangeDeclare("direct_exchange", BuiltinExchangeType.DIRECT);
        channel.queueBind("direct_queue1","direct_exchange","error");
        channel.queueBind("direct_queue2","direct_exchange","error");
        channel.queueBind("direct_queue2","direct_exchange","info");
        channel.queueBind("direct_queue2","direct_exchange","warning");

        //4. p
        channel.basicPublish("direct_exchange","error",null,"message one!".getBytes());
        channel.basicPublish("direct_exchange","info",null,"message two!".getBytes());
        channel.basicPublish("direct_exchange","xxx",null,"message three!".getBytes());

        //5. c
        channel.close();
        connection.close();


    }


}
